<?php


  require('includes/application_top.php');

  if (!tep_session_is_registered('customer_id')) {
    $navigation->set_snapshot();
    tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  }

  if (!isset($HTTP_GET_VARS['order_id']) || (isset($HTTP_GET_VARS['order_id']) && !is_numeric($HTTP_GET_VARS['order_id']))) {
    tep_redirect(tep_href_link('orders_product_history.php', '', 'SSL'));
  }

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ACCOUNT_HISTORY_INFO);

  $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
  $breadcrumb->add('Lịch sử', tep_href_link('orders_product_history.php', '', 'SSL'));
  $breadcrumb->add(sprintf('Đặt hàng ', $HTTP_GET_VARS['order_id']), tep_href_link('orders_product_history.php', 'order_id=' . $HTTP_GET_VARS['order_id'], 'SSL'));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="690px" cellspacing="0" cellpadding="0" class="table_muahang">
<?php
    $orders_product_query = tep_db_query("select * from orders_new where orders_id =".$HTTP_GET_VARS['order_id']);
    while ($orders_product = tep_db_fetch_array($orders_product_query)) {
        
        $account_query = tep_db_query("select * from " . TABLE_CUSTOMERS . " where customers_id = '" . $orders_product['customers_id'] . "'");
        $account = tep_db_fetch_array($account_query);
        
        $orders_status_query = tep_db_query("select * from orders_new_status where status_id = '" . $orders_product['status_id'] . "'");
        $orders_status = tep_db_fetch_array($orders_status_query);
        if($orders_status['status_id'] == 0){ $status_name = "Chờ xử lý"; }else{ $status_name = $orders_status['status_name']; }
        
        $address_query = tep_db_query("select * from " . TABLE_ADDRESS_BOOK . " where address_book_id = '" . (int)$account['customers_default_address_id'] . "'");
        $address = tep_db_fetch_array($address_query);
        
        $country_query = tep_db_query("select * from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$address['entry_country_id'] . "'");
        $country = tep_db_fetch_array($country_query);
?>      
      <div class="home-newprodbar">
                    <div class="lblTitle"><?php echo 'Đơn hàng số: '. $HTTP_GET_VARS['order_id'] . ' <small>(' . $status_name . ')</small>'; ?></div>
                </div><br /><br /><br />    
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td class="smallText"><?php echo HEADING_ORDER_DATE . ' ' . tep_date_short($orders_product['created']); ?></td>
          </tr>
        </table></td>
      </tr>      
      
        <tr><td class="title_orders" colspan="2"><br />Thông tin khách hàng</td></tr>
        <tr>
            <td class="field">Tên Khách Hàng:</td>
            <td><?php echo ''.$account['customers_firstname'].' '.$account['customers_lastname']; ?></td>
        </tr>
        <tr>
            <td class="field">Điện thoại:</td>
            <td><?php echo ''.$account['customers_telephone']; ?></td>
        </tr>
        <tr>
            <td class="field">Địa chỉ:</td>
            <td>
                <?php echo $address['entry_street_address'].' '.$address['entry_suburb'].' '.$address['entry_state'].' '.$address['entry_city']; ?>
                <?php echo ' '.$country['countries_name']; ?>    
            </td>
        </tr>
        <tr>
            <td class="field">Fax:</td>
            <td><?php echo ''.$account['customers_fax']; ?></td>
        </tr>
        <tr>
            <td class="field">E-mail:</td>
            <td><?php echo ''.$account['customers_email_address']; ?></td>
        </tr>
        <tr><td class="title_orders" colspan="2"><br />Thông tin sản phẩm:</td></tr>
        <tr><td colspan="2">            
            <table border="0" cellpadding="2" cellspacing="2" width="690px">
              <tr bgcolor="#EFEFEF">
                <td align="center" style="font-weight: bold;">STT</td>
                <td align="center" style="font-weight: bold;">Hình ảnh</td>
                <td align="center" style="font-weight: bold;">Số lượng</td>
                <td align="center" style="font-weight: bold;">Liên kết</td>
                <td align="center" style="font-weight: bold;">Giá</td>
              </tr>      
              <?php
                $stt = 1;
                $product_query = tep_db_query("select * from orders_new_product where orders_id = '".$HTTP_GET_VARS['order_id']."' order by orders_product_id");
                while ($product = tep_db_fetch_array($product_query)) {
              ?>
              <tr>
                <td align="center"><?php echo $stt; ?></td>
                <td align="center"><img src="<?php echo $product['images_url']; ?>" width="100px" /></td>
                <td align="center"><?php echo $product['quanlity']; ?></td>
                <td align="center"><?php echo $product['weblink']; ?></td>
                <td align="center">
                <?php
                if($product['currency'] == 'VND'){ 
                    echo $currencies->display_price($product['price'], tep_get_tax_rate($product['products_tax_class_id']));
                }else{echo $product['price'].' '.$product['currency'];} 
                ?>    
                </td>
              </tr>
              <?php $stt++; } ?>
              </table>
        </td></tr>
        <?php        
            $store_query = tep_db_query("select * from " . TABLE_CONFIGURATION . " where configuration_id = '1'");
            $store = tep_db_fetch_array($store_query);                
        ?>
        <?php if($orders_product['price_reply']){ ?>
        <tr><td class="title_orders" colspan="2"><br />Phản hồi từ <?php echo $store['configuration_value']; ?></td></tr>
        <tr>
            <td class="field">Thông tin phản hồi:</td>
            <td>
            <?php if($orders_product['currency_reply']=='USD'){ ?>
                <table border="0" width="100%" cellspacing="2" cellpadding="2">
                <?php
                    $price_reply = explode(',', $orders_product['price_reply']); 
                    $product_orders_query = tep_db_query("select * from orders_new_product where orders_id=".$HTTP_GET_VARS['order_id']);
                    $stt_product = 1;
                    while($product_orders_values = tep_db_fetch_array($product_orders_query)){
                        echo '<tr><td>Số lượng sản phẩm '.$stt_product.': </td><td>'.$product_orders_values['quanlity'].'</td></tr>';
                        echo '<tr><td>Giá sản phẩm '.$stt_product.': </td><td>'.$price_reply[$stt_product-1].' '.$orders_product['currency_reply'].'</td></tr>';  
                    $stt_product++;
                    }
                ?>
                <tr><td>Thuế: </td><td><?php echo $orders_product['tax_reply'].' '.$orders_product['currency_reply']; ?></td></tr>
                <tr><td>Chi phí vận chuyển: </td><td><?php echo $orders_product['ship_reply'].' '.$orders_product['currency_reply']; ?></td></tr>
                <tr><td><b>Tổng cộng: </b></td>
                    <td><br /><b>
                        <?php
                            $sum_price = array_sum($price_reply) + $orders_product['tax_reply'] + $orders_product['ship_reply']; 
                            echo $sum_price.' '.$orders_product['currency_reply'];
                        ?>
                    </b></td>
                </tr>
                </table>
            <?php }else{ ?>
                <table border="0" width="100%" cellspacing="2" cellpadding="2">
                <?php
                    $price_reply = explode(',', $orders_product['price_reply']); 
                    $product_orders_query = tep_db_query("select * from orders_new_product where orders_id=".$HTTP_GET_VARS['order_id']);
                    $stt_product = 1;
                    while($product_orders_values = tep_db_fetch_array($product_orders_query)){
                        echo '<tr><td>Số lượng sản phẩm '.$stt_product.': </td><td>'.$product_orders_values['quanlity'].'</td></tr>';
                        echo '<tr><td>Giá sản phẩm '.$stt_product.': </td><td>'.$currencies->format($price_reply[$stt_product-1]).'</td></tr>';  
                    $stt_product++;
                    }
                ?>
                <tr><td>Thuế: </td><td><?php echo $currencies->format($orders_product['tax_reply']); ?></td></tr>
                <tr><td>Chi phí vận chuyển: </td><td><?php echo $currencies->format($orders_product['ship_reply']); ?></td></tr>
                <tr><td><b>Tổng cộng: </b></td>
                    <td><br /><b>
                        <?php
                            $sum_price = array_sum($price_reply) + $orders_product['tax_reply'] + $orders_product['ship_reply']; 
                            echo $currencies->format($sum_price);
                        ?>
                    </b></td>
                </tr>
                </table>
            <?php } ?>
            </td>
        </tr>    
        <?php } ?>
      
      <tr>
        <td align="right" colspan="2">
            <br /><br /><?php echo '<a href="' . tep_href_link('orders_product_history.php', tep_get_all_get_params(array('order_id')), 'SSL') . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
        </td>
      </tr>
<?php
    }
?>
    </table></td>
<!-- body_text_eof //-->
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
    </table></td>
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
